
<!DOCTYPE html>
<html>
<head>

<title>新增我的测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit">
<link rel="stylesheet" href="/ui2/src/css/layui.css" media="all" />
<link rel="stylesheet" href="/ui2/css/public.css" media="all" />
<link rel="stylesheet" type="text/css" href="/ui/eova/css/eova.css">

<!--  <link rel="stylesheet" href="http://www.layui.com/admin/std/dist/layuiadmin/style/admin.css" media="all"> -->

<script type="text/javascript" src="/ui/js/jquery.min.js"></script>
<script type="text/javascript" src="/ui/js/json2-min.js"></script>

<script type="text/javascript" src="/ui/js/common.js"></script>
<script type="text/javascript" src="/ui/js/string.js"></script>

<script type="text/javascript" src="/ui2/src/layui.js"></script>
<script type="text/javascript" src="/ui2/js/DataTableExtend.js"></script>

<!-- <script type="text/javascript" src="http://yelog.org/layui-select-multiple/layui/layui.js"></script> -->

<!-- <script type="text/javascript" src="../../ui2/js/dataList.js"></script> -->





<script type="text/javascript"
	src="/plugins/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>



<script type="text/javascript" src="/plugins/format/jsformat.js"></script>

<script type="text/javascript" src="/ui/easy/easy.min.js"></script>
<script type="text/javascript" src="/ui/eova/eova.min.js"></script>
<script type="text/javascript" src="/ui/eova/src/eova.find.js"></script>



<script>
	String.prototype.replaceAll = function(s1, s2) {
		return this.replace(new RegExp(s1, "gm"), s2);
	}
	// 全局JS常量配置
	var IMG = "http://127.0.0.1:8080/file";
	var FILE = "http://127.0.0.1:8080/file";
	var FILE_MAX = "5120";
	var IMG_MAX = "5120";

	//类似 .jpg|.gif|.png|.bmp
	var UPLOAD_IMG_TYPE = ".jpeg|.jpg|.gif|.png|.bmp".replaceAll('\\.', '');
	var UPLOAD_FILE_TYPE = ".jpg|.jepg|.gif|.png|.bmp|.gz|.7z|.rar|.zip|.swf|.mp3|.mp4|.jar|.apk|.ipa|.doc|.docx|.xls|.xlsx|.ppt|.pptx|.pdf|.txt"
			.replaceAll('\\.', '');
	//刷新此页面
	var refresh = function() {
		location.reload();
	};

	//页面类型 add/update/detail/examine
	var PAGE_TYPE = "add";

	//监听页面大小
	var layerInitWidth;
	var layerInitHeight;
</script>
<style>
</style>
</head>

<link rel="stylesheet" href="/ui2/css/admin.css" media="all">
<link href="/plugins/umeditor/themes/default/css/umeditor.css"
	type="text/css" rel="stylesheet">
<!--     <script type="text/javascript" src="third-party/jquery.min.js"></script> -->
<script type="text/javascript" charset="utf-8"
	src="/plugins/umeditor/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8"
	src="/plugins/umeditor/umeditor.min.js">
	
</script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8"
	src="/plugins/umeditor/lang/zh-cn/zh-cn.js"></script>
<body>
	<form id="addFormdemo2_test" name="addFormdemo2_test" method="post"
		class="layui-form">
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">

					<div class="layui-card">
						<div class="layui-card-header">面板1</div>
						<div class="layui-card-body">
							<div class="layui-row layui-col-space10 layui-form-item">

								<div class="layui-col-lg3">
									<label class="layui-form-label" title="姓名[name]"> 姓名</label>
									<div class="layui-input-block">

										<input type="text" id="name" name="name" value=""
											placeholder="" lay-verify="length[2~5]" autocomplete="off"
											class="layui-input">
									</div>
								</div>


								<div class="layui-col-lg3">
									<label class="layui-form-label" title="密码[password]"> <font
										size="4" face="arial" color="red">*</font> 密码
									</label>
									<div class="layui-input-block">

										<input type="password" id="password" name="password" value=""
											lay-verify="required|length[6~10]" placeholder="请输入密码"
											autocomplete="off" class="layui-input">
									</div>
								</div>

							</div>
							<div class="layui-row layui-col-space10 layui-form-item">

								<div class="layui-col-lg3">
									<label class="layui-form-label" title="是否有效[status]">
										是否有效</label>
									<div class="layui-input-block">

										<input type="checkbox" id="status_checkbox"
											name="status_checkbox" lay-skin="switch"
											lay-filter="status_checkbox" lay-text="是|否" checked>
										<input type="hidden" id="status" name="status" value="on">
										<script>
											layui
													.use(
															[ 'form' ],
															function() {
																var form = layui.form;
																//监听指定开关
																form
																		.on(
																				'switch(status_checkbox)',
																				function(
																						data) {
																					if (this.checked) {
																						$(
																								"#status")
																								.val(
																										"on");
																					} else {
																						$(
																								"#status")
																								.val(
																										"off");
																					}
																				});
															});
										</script>
									</div>
								</div>

							</div>






						</div>
					</div>
				</div>

				<div class="layui-card">
					<div class="layui-card-header">面板2</div>
					<div class="layui-card-body">
						<div class="layui-row layui-col-space10 layui-form-item">

							<div class="layui-col-lg4">
								<label class="layui-form-label" title="喜好1[tag1]"> <font
									size="4" face="arial" color="red">*</font> 喜好1
								</label>
								<div class="layui-input-block">

									<select id="tag1" name="tag1" lay-filter="tag1"
										url="/widget/comboJson/demo2_test-tag1" lay-verify="required"
										multiple lay-search>
										<!--         <option value="">请选择</option> -->

										<!--         <option value="0">写作</option> -->
										<!--         <option value="1" >阅读</option> -->
										<!--         <option value="2">游戏</option> -->
										<!--         <option value="3">音乐</option> -->
										<!--         <option value="4">旅行</option> -->

									</select>
									<script type="text/javascript">
										var tag1_init = function() {
											//清除本节点数据（子节点也要执行初始）
											$("#tag1").empty();
											//检查是否有子节点需要刷新数据
											var pid = $('select[pid="tag1"]');
											if (pid.length != 0) {
												//关联初始
												var funName = pid.attr("id")
														+ "_init";
												//tag1_init
												if (isExitsFunction(funName)) {
													//funName();
													//alert(funName);
													//dataDone(res, curr, count,is_single);
													eval(funName + "();");

												}
											}

											// 手动赋值(可能存在级联关系)
											$
													.ajax({
														url : '/widget/comboJson/demo2_test-tag1',
														type : 'get',
														success : function(data) {

															var objects = eval(data);
															var pidKey = null;
															var pidValue = null;
															//判断是否有
															//select areaId ID,areaName CN,parentid p_id from table//如果存在ID，CN之外的字段则认为是关联的,并且指定了父节点是谁
															if (objects.length >= 2) {//
																var object = objects[1];
																for (i in object) {
																	//console.log(i);
																	if (i != 'id'
																			&& i != 'cn') {
																		pidKey = i;
																		break;
																	}
																}
															}

															if (pidKey != null) {
																//如果存在 
																$(
																		'select[id="tag1"]')
																		.attr(
																				"pid",
																				pidKey);
																pidValue = $(
																		'select[id="'
																				+ pidKey
																				+ '"]')
																		.val();
															}
															//检测父节点是否有值才渲染|| 无父节点也渲染
															console
																	.log('pidValue:'
																			+ pidValue);
															if (pidKey == null
																	|| (pidValue != null && pidValue != '')) {

																$(objects)
																		.each(
																				function(
																						index) {
																					if (index == 0) {
																						$(
																								"#tag1")
																								.append(
																										'<option value="">请选择</option>');
																					}

																					var object = objects[index];
																					if (pidKey == null) {
																						var optionStr = "";
																						optionStr += "<option value='" + object.id + "'>"
																								+ object.cn
																								+ "</option>";
																						$(
																								"#tag1")
																								.append(
																										optionStr);
																					} else {
																						if (object[pidKey] == pidValue) {
																							var optionStr = "";
																							optionStr += "<option value='" + object.id + "'>"
																									+ object.cn
																									+ "</option>";
																							$(
																									"#tag1")
																									.append(
																											optionStr);
																						}
																					}
																				});

																if ('' != '')
																	$(
																			'select[id="tag1"]')
																			.val(
																					''
																							.split(','));

															}
															renderForm();//由于前部还有一个重置options的操作
														}
													});
										}
										tag1_init();
										layui
												.use(
														[ 'form' ],
														function() {
															var form = layui.form;
															//选中事件
															form
																	.on(
																			'select(tag1)',
																			function(
																					data) {
																				console
																						.log(data);
																				//检查是否有子节点需要刷新数据
																				var pid = $('select[pid="tag1"]');
																				if (pid.length != 0) {
																					//关联初始
																					var funName = pid
																							.attr("id")
																							+ "_init";
																					//tag1_init
																					if (isExitsFunction(funName)) {
																						//funName();
																						//alert(funName);
																						//dataDone(res, curr, count,is_single);
																						eval(funName
																								+ "();");

																					}
																				}

																			});
														});
									</script>
								</div>
							</div>


							<div class="layui-col-lg4">
								<label class="layui-form-label" title="喜好2[tag2]"> <font
									size="4" face="arial" color="red">*</font> 喜好2
								</label>
								<div class="layui-input-block">

									<select id="tag2" name="tag2" lay-filter="tag2"
										url="/widget/comboJson/demo2_test-tag2" lay-verify="required"
										lay-search>
										<!--         <option value="">请选择</option> -->

										<!--         <option value="0">写作</option> -->
										<!--         <option value="1" >阅读</option> -->
										<!--         <option value="2">游戏</option> -->
										<!--         <option value="3">音乐</option> -->
										<!--         <option value="4">旅行</option> -->

									</select>
									<script type="text/javascript">
										var tag2_init = function() {
											//清除本节点数据（子节点也要执行初始）
											$("#tag2").empty();
											//检查是否有子节点需要刷新数据
											var pid = $('select[pid="tag2"]');
											if (pid.length != 0) {
												//关联初始
												var funName = pid.attr("id")
														+ "_init";
												//tag2_init
												if (isExitsFunction(funName)) {
													//funName();
													//alert(funName);
													//dataDone(res, curr, count,is_single);
													eval(funName + "();");

												}
											}

											// 手动赋值(可能存在级联关系)
											$
													.ajax({
														url : '/widget/comboJson/demo2_test-tag2',
														type : 'get',
														success : function(data) {

															var objects = eval(data);
															var pidKey = null;
															var pidValue = null;
															//判断是否有
															//select areaId ID,areaName CN,parentid p_id from table//如果存在ID，CN之外的字段则认为是关联的,并且指定了父节点是谁
															if (objects.length >= 2) {//
																var object = objects[1];
																for (i in object) {
																	//console.log(i);
																	if (i != 'id'
																			&& i != 'cn') {
																		pidKey = i;
																		break;
																	}
																}
															}

															if (pidKey != null) {
																//如果存在 
																$(
																		'select[id="tag2"]')
																		.attr(
																				"pid",
																				pidKey);
																pidValue = $(
																		'select[id="'
																				+ pidKey
																				+ '"]')
																		.val();
															}
															//检测父节点是否有值才渲染|| 无父节点也渲染
															console
																	.log('pidValue:'
																			+ pidValue);
															if (pidKey == null
																	|| (pidValue != null && pidValue != '')) {

																$(objects)
																		.each(
																				function(
																						index) {
																					if (index == 0) {
																						$(
																								"#tag2")
																								.append(
																										'<option value="">请选择</option>');
																					}

																					var object = objects[index];
																					if (pidKey == null) {
																						var optionStr = "";
																						optionStr += "<option value='" + object.id + "'>"
																								+ object.cn
																								+ "</option>";
																						$(
																								"#tag2")
																								.append(
																										optionStr);
																					} else {
																						if (object[pidKey] == pidValue) {
																							var optionStr = "";
																							optionStr += "<option value='" + object.id + "'>"
																									+ object.cn
																									+ "</option>";
																							$(
																									"#tag2")
																									.append(
																											optionStr);
																						}
																					}
																				});

																if ('' != '')
																	$(
																			'select[id="tag2"]')
																			.val(
																					''
																							.split(','));

															}
															renderForm();//由于前部还有一个重置options的操作
														}
													});
										}
										tag2_init();
										layui
												.use(
														[ 'form' ],
														function() {
															var form = layui.form;
															//选中事件
															form
																	.on(
																			'select(tag2)',
																			function(
																					data) {
																				console
																						.log(data);
																				//检查是否有子节点需要刷新数据
																				var pid = $('select[pid="tag2"]');
																				if (pid.length != 0) {
																					//关联初始
																					var funName = pid
																							.attr("id")
																							+ "_init";
																					//tag2_init
																					if (isExitsFunction(funName)) {
																						//funName();
																						//alert(funName);
																						//dataDone(res, curr, count,is_single);
																						eval(funName
																								+ "();");

																					}
																				}

																			});
														});
									</script>
								</div>
							</div>


							<div class="layui-col-lg4">
								<label class="layui-form-label" title="产品[relation_pro]">
									<font size="4" face="arial" color="red">*</font> 产品
								</label>
								<div class="layui-input-block">


									<div class="layui-input">
										<input type="text" id="relation_pro_show"
											name="relation_pro_show" placeholder="请选择" class="tags-input">
										<input type="hidden" id="relation_pro" name="relation_pro"
											value="" lay-verify="required" title='产品'>
									</div>

									<script type="text/javascript">
										$(function() {

											var initrelation_proData = function() {
												// 手动赋值,如果有值的花
												$
														.ajax({
															url : ''
																	+ "/widget/findCnByEn/demo2_test-relation_pro-",
															type : 'get',
															success : function(
																	data) {

																var objShow = $('#relation_pro_show');
																var obj = $('#relation_pro');

																var object = eval(data);
																var text_field_name = object.text_field;
																var text_field_id = null;
																var objects = eval(object.data);

																for ( var key in objects[0]) {
																	if (key != text_field_name) {
																		text_field_id = key;
																		break;
																	}
																}

																for (
																		j = 0,
																		len = objects.length; j < len; j++) {
																	var one = objects[j];
																	if (j == 0)
																		addTag(
																				objShow,
																				obj,
																				one[text_field_id],
																				one[text_field_name],
																				true);
																	else
																		addTag(
																				objShow,
																				obj,
																				one[text_field_id],
																				one[text_field_name],
																				false);
																}

															}
														});
											}
											if ('' != '') {
												initrelation_proData();
											}

											//如果是只读模式，则事件移除
											//tag移除事件
											$(document)
													.on(
															'click',
															'.relation_pro',
															function(obj) {
																// console.log(obj.target.parentNode);//标准 

																if ($(
																		"#relation_pro_show")
																		.attr(
																				'readonly') != "readonly")
																	removeTag(obj.target);
															});
											//点击事件
											$("#relation_pro_show")
													.click(
															function() {
																if ($(
																		"#relation_pro_show")
																		.attr(
																				'readonly') != "readonly")
																	tagchoice(
																			$('#relation_pro_show'),
																			$('#relation_pro'),
																			'/widget/find?code=demo2_test&field=relation_pro&template=lay',
																			false);
															});

										});
									</script>
								</div>
							</div>

						</div>
						<div class="layui-row layui-col-space10 layui-form-item">

							<div class="layui-col-lg6">
								<label class="layui-form-label" title="头像[avatar]"> <font
									size="4" face="arial" color="red">*</font> 头像
								</label>
								<div class="layui-input-block">



									<div class="layui-upload">
										<button type="button" class="layui-btn" id="avatar_button"
											name="avatar_button">上传图片</button>
										<div class="layui-upload-list">
											<input type="hidden" id="avatar" name="avatar" value=""
												lay-verify="required" title='头像' /> <img
												class="layui-upload-img" id="avatar_img" src="">
											<p id="avatar_text"></p>
										</div>
									</div>


									<script>
										layui
												.use(
														'upload',
														function() {
															var $ = layui.jquery, upload = layui.upload;

															//普通图片上传
															var uploadInst_avatar = upload
																	.render({
																		elem : '#avatar_button',
																		url : '/upload/img?name=avatar_file&filedir=',
																		size : IMG_MAX //限制文件大小，单位 KB
																		,
																		accept : 'file',
																		exts : UPLOAD_IMG_TYPE,
																		acceptMime : 'image/*' //（只显示图片文件） 2.2.6 开始新增
																		,
																		field : 'avatar_file',
																		before : function(
																				obj) {
																			//预读本地文件示例，不支持ie8
																			obj
																					.preview(function(
																							index,
																							file,
																							result) {
																						$(
																								'#avatar_img')
																								.attr(
																										'style',
																										'height: 100px;max-width: 360px;');
																						$(
																								'#avatar_img')
																								.attr(
																										'src',
																										result); //图片链接（base64）
																					});
																		},
																		done : function(
																				res) {
																			//如果上传失败
																			if (res.success == false) {
																				return layer
																						.msg('上传失败');
																			}
																			//上传成功
																			$(
																					'#avatar')
																					.attr(
																							'value',
																							res.fileName);
																		},
																		error : function() {
																			//演示失败状态，并实现重传
																			var demoText = $('#avatar_text');
																			demoText
																					.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini img-reload_avatar">重试</a>');
																			demoText
																					.find(
																							'.img-reload_avatar')
																					.on(
																							'click',
																							function() {
																								uploadInst_avatar
																										.upload();
																							});
																		}
																	});
														});

										$(function() {
											var $input = $('#avatar');

											var htmlOptions = eval('({})');
											if (htmlOptions.isReadonly) {
												$input.parent().mask();
												return;
											}

											// init input file
											$('.eova-file')
													.each(
															function() {
																var offset = $(
																		this)
																		.find(
																				'input[type=text]')
																		.offset();
																$(this)
																		.find(
																				'input[type=file]')
																		.css(
																				{
																					left : offset.left - 1,
																					// top : offset.top-1,
																					width : $(
																							this)
																							.width()
																				});
															});

											// 异步传图(动态绑定事件)
											var myfun = function() {

												var $this_file = $("#avatar_file");
												console.log($this_file.val());
												$input.val($this_file.val());
												var reader = new FileReader();
												var files = $this_file
														.prop('files');
												reader.readAsDataURL(files[0]);
												reader.onload = function(e) {
													$this_file.parent().find(
															'img').attr('src',
															e.target.result);
												}

												$input.val("Loading...");

												$('#avatar_file')
														.upload(
																{
																	action : '/upload/img?name=avatar_file&filedir=',
																	name : "avatar_file",
																	onsuccess : function(
																			json) {
																		$input
																				.val(json.fileName);
																	}
																});
											};

											$(document).on("change",
													"#avatar_file", myfun);

										});
									</script>
								</div>
							</div>


							<div class="layui-col-lg6">
								<label class="layui-form-label" title="附件[file]"> <font
									size="4" face="arial" color="red">*</font> 附件
								</label>
								<div class="layui-input-block">

									<div class="layui-upload">
										<button type="button" class="layui-btn" id="file_button"
											name="file_button">选择文件</button>
										<div class="layui-upload-list">
											<input type="hidden" id="file" name="file" title='附件'
												lay-verify="required" value="" />
											<p id="file_text"></p>
										</div>
									</div>

									<script>
										// 目前只支持单文件

										layui
												.use(
														'upload',
														function() {
															var $ = layui.jquery, upload = layui.upload;

															//初始

															//普通文件上传
															var uploadInst_file = upload
																	.render({
																		elem : '#file_button',
																		url : '/upload/file?name=file_file&filedir=',
																		size : FILE_MAX //限制文件大小，单位 KB
																		,
																		accept : 'file',
																		exts : UPLOAD_FILE_TYPE,
																		field : 'file_file',
																		before : function(
																				obj) {
																			//预读本地文件示例，不支持ie8
																			obj
																					.preview(function(
																							index,
																							file,
																							result) {
																						var demoText = $('#file_text');
																						demoText
																								.html('<span class="layui-inline layui-upload-choose">'
																										+ file.name
																										+ '</span>');
																					});
																		}

																		//,multiple: true
																		// ,bindAction: '#file_button_begin'
																		,
																		done : function(
																				res) {
																			//如果文件上传失败
																			if (res.success == false) {
																				$(
																						'#file')
																						.attr(
																								'value',
																								"");
																				return layer
																						.msg('上传失败:'
																								+ res.msg);
																			}
																			//上传成功
																			$(
																					'#file')
																					.attr(
																							'value',
																							res.fileName);

																			var demoText = $('#file_text');
																			var fileName = demoText
																					.text();

																			showFile_file(
																					res.fileName,
																					fileName);
																		},
																		error : function() {
																			//演示失败状态，并实现重传
																			var demoText = $('#file_text');
																			demoText
																					.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini file-reload_file">重试</a>');
																			demoText
																					.find(
																							'.file-reload_file')
																					.on(
																							'click',
																							function() {
																								uploadInst_file
																										.upload();
																							});
																		}
																	});
														});

										//path 为局部地址如：/upload/aaa.jpg,name=/upload/aaa.jpg或者 aaa.jpg即可
										function showFile_file(path, name) {
											var demoText = $('#file_text');
											var url = '';
											if (path != '') {
												if (path.indexOf("http://") == -1) {

													url = 'http://127.0.0.1:8080/file'
															+ '/' + path;
												} else
													url = path;
											}

											//文件名需要 ‘/111/a.jpg’=》裁剪成 a.jpg （如果出现的话）
											var index = name.lastIndexOf('/');
											if (index != -1)
												name = name
														.substring(index + 1);

											demoText
													.html('<a href="'+url+'" target="view_window"><span class="layui-inline layui-upload-choose">'
															+ name
															+ '</span></a>');
										}
									</script>
								</div>
							</div>

						</div>
						<div class="layui-row layui-col-space10 layui-form-item">

							<div class="layui-col-lg4">
								<label class="layui-form-label" title="省[p_id]"> 省</label>
								<div class="layui-input-block">

									<select id="p_id" name="p_id" lay-filter="p_id"
										url="/widget/comboJson/demo2_test-p_id" lay-verify=""
										lay-search>
										<!--         <option value="">请选择</option> -->

										<!--         <option value="0">写作</option> -->
										<!--         <option value="1" >阅读</option> -->
										<!--         <option value="2">游戏</option> -->
										<!--         <option value="3">音乐</option> -->
										<!--         <option value="4">旅行</option> -->

									</select>
									<script type="text/javascript">
										var p_id_init = function() {
											//清除本节点数据（子节点也要执行初始）
											$("#p_id").empty();
											//检查是否有子节点需要刷新数据
											var pid = $('select[pid="p_id"]');
											if (pid.length != 0) {
												//关联初始
												var funName = pid.attr("id")
														+ "_init";
												//p_id_init
												if (isExitsFunction(funName)) {
													//funName();
													//alert(funName);
													//dataDone(res, curr, count,is_single);
													eval(funName + "();");

												}
											}

											// 手动赋值(可能存在级联关系)
											$
													.ajax({
														url : '/widget/comboJson/demo2_test-p_id',
														type : 'get',
														success : function(data) {

															var objects = eval(data);
															var pidKey = null;
															var pidValue = null;
															//判断是否有
															//select areaId ID,areaName CN,parentid p_id from table//如果存在ID，CN之外的字段则认为是关联的,并且指定了父节点是谁
															if (objects.length >= 2) {//
																var object = objects[1];
																for (i in object) {
																	//console.log(i);
																	if (i != 'id'
																			&& i != 'cn') {
																		pidKey = i;
																		break;
																	}
																}
															}

															if (pidKey != null) {
																//如果存在 
																$(
																		'select[id="p_id"]')
																		.attr(
																				"pid",
																				pidKey);
																pidValue = $(
																		'select[id="'
																				+ pidKey
																				+ '"]')
																		.val();
															}
															//检测父节点是否有值才渲染|| 无父节点也渲染
															console
																	.log('pidValue:'
																			+ pidValue);
															if (pidKey == null
																	|| (pidValue != null && pidValue != '')) {

																$(objects)
																		.each(
																				function(
																						index) {
																					if (index == 0) {
																						$(
																								"#p_id")
																								.append(
																										'<option value="">请选择</option>');
																					}

																					var object = objects[index];
																					if (pidKey == null) {
																						var optionStr = "";
																						optionStr += "<option value='" + object.id + "'>"
																								+ object.cn
																								+ "</option>";
																						$(
																								"#p_id")
																								.append(
																										optionStr);
																					} else {
																						if (object[pidKey] == pidValue) {
																							var optionStr = "";
																							optionStr += "<option value='" + object.id + "'>"
																									+ object.cn
																									+ "</option>";
																							$(
																									"#p_id")
																									.append(
																											optionStr);
																						}
																					}
																				});

																if ('' != '')
																	$(
																			'select[id="p_id"]')
																			.val(
																					''
																							.split(','));

															}
															renderForm();//由于前部还有一个重置options的操作
														}
													});
										}
										p_id_init();
										layui
												.use(
														[ 'form' ],
														function() {
															var form = layui.form;
															//选中事件
															form
																	.on(
																			'select(p_id)',
																			function(
																					data) {
																				console
																						.log(data);
																				//检查是否有子节点需要刷新数据
																				var pid = $('select[pid="p_id"]');
																				if (pid.length != 0) {
																					//关联初始
																					var funName = pid
																							.attr("id")
																							+ "_init";
																					//p_id_init
																					if (isExitsFunction(funName)) {
																						//funName();
																						//alert(funName);
																						//dataDone(res, curr, count,is_single);
																						eval(funName
																								+ "();");

																					}
																				}

																			});
														});
									</script>
								</div>
							</div>


							<div class="layui-col-lg4">
								<label class="layui-form-label" title="市[c_id]"> 市</label>
								<div class="layui-input-block">

									<select id="c_id" name="c_id" lay-filter="c_id"
										url="/widget/comboJson/demo2_test-c_id" lay-verify=""
										lay-search>
										<!--         <option value="">请选择</option> -->

										<!--         <option value="0">写作</option> -->
										<!--         <option value="1" >阅读</option> -->
										<!--         <option value="2">游戏</option> -->
										<!--         <option value="3">音乐</option> -->
										<!--         <option value="4">旅行</option> -->

									</select>
									<script type="text/javascript">
										var c_id_init = function() {
											//清除本节点数据（子节点也要执行初始）
											$("#c_id").empty();
											//检查是否有子节点需要刷新数据
											var pid = $('select[pid="c_id"]');
											if (pid.length != 0) {
												//关联初始
												var funName = pid.attr("id")
														+ "_init";
												//c_id_init
												if (isExitsFunction(funName)) {
													//funName();
													//alert(funName);
													//dataDone(res, curr, count,is_single);
													eval(funName + "();");

												}
											}

											// 手动赋值(可能存在级联关系)
											$
													.ajax({
														url : '/widget/comboJson/demo2_test-c_id',
														type : 'get',
														success : function(data) {

															var objects = eval(data);
															var pidKey = null;
															var pidValue = null;
															//判断是否有
															//select areaId ID,areaName CN,parentid p_id from table//如果存在ID，CN之外的字段则认为是关联的,并且指定了父节点是谁
															if (objects.length >= 2) {//
																var object = objects[1];
																for (i in object) {
																	//console.log(i);
																	if (i != 'id'
																			&& i != 'cn') {
																		pidKey = i;
																		break;
																	}
																}
															}

															if (pidKey != null) {
																//如果存在 
																$(
																		'select[id="c_id"]')
																		.attr(
																				"pid",
																				pidKey);
																pidValue = $(
																		'select[id="'
																				+ pidKey
																				+ '"]')
																		.val();
															}
															//检测父节点是否有值才渲染|| 无父节点也渲染
															console
																	.log('pidValue:'
																			+ pidValue);
															if (pidKey == null
																	|| (pidValue != null && pidValue != '')) {

																$(objects)
																		.each(
																				function(
																						index) {
																					if (index == 0) {
																						$(
																								"#c_id")
																								.append(
																										'<option value="">请选择</option>');
																					}

																					var object = objects[index];
																					if (pidKey == null) {
																						var optionStr = "";
																						optionStr += "<option value='" + object.id + "'>"
																								+ object.cn
																								+ "</option>";
																						$(
																								"#c_id")
																								.append(
																										optionStr);
																					} else {
																						if (object[pidKey] == pidValue) {
																							var optionStr = "";
																							optionStr += "<option value='" + object.id + "'>"
																									+ object.cn
																									+ "</option>";
																							$(
																									"#c_id")
																									.append(
																											optionStr);
																						}
																					}
																				});

																if ('' != '')
																	$(
																			'select[id="c_id"]')
																			.val(
																					''
																							.split(','));

															}
															renderForm();//由于前部还有一个重置options的操作
														}
													});
										}
										c_id_init();
										layui
												.use(
														[ 'form' ],
														function() {
															var form = layui.form;
															//选中事件
															form
																	.on(
																			'select(c_id)',
																			function(
																					data) {
																				console
																						.log(data);
																				//检查是否有子节点需要刷新数据
																				var pid = $('select[pid="c_id"]');
																				if (pid.length != 0) {
																					//关联初始
																					var funName = pid
																							.attr("id")
																							+ "_init";
																					//c_id_init
																					if (isExitsFunction(funName)) {
																						//funName();
																						//alert(funName);
																						//dataDone(res, curr, count,is_single);
																						eval(funName
																								+ "();");

																					}
																				}

																			});
														});
									</script>
								</div>
							</div>


							<div class="layui-col-lg4">
								<label class="layui-form-label" title="区[a_id]"> 区</label>
								<div class="layui-input-block">

									<select id="a_id" name="a_id" lay-filter="a_id"
										url="/widget/comboJson/demo2_test-a_id" lay-verify=""
										lay-search>
										<!--         <option value="">请选择</option> -->

										<!--         <option value="0">写作</option> -->
										<!--         <option value="1" >阅读</option> -->
										<!--         <option value="2">游戏</option> -->
										<!--         <option value="3">音乐</option> -->
										<!--         <option value="4">旅行</option> -->

									</select>
									<script type="text/javascript">
										var a_id_init = function() {
											//清除本节点数据（子节点也要执行初始）
											$("#a_id").empty();
											//检查是否有子节点需要刷新数据
											var pid = $('select[pid="a_id"]');
											if (pid.length != 0) {
												//关联初始
												var funName = pid.attr("id")
														+ "_init";
												//a_id_init
												if (isExitsFunction(funName)) {
													//funName();
													//alert(funName);
													//dataDone(res, curr, count,is_single);
													eval(funName + "();");

												}
											}

											// 手动赋值(可能存在级联关系)
											$
													.ajax({
														url : '/widget/comboJson/demo2_test-a_id',
														type : 'get',
														success : function(data) {

															var objects = eval(data);
															var pidKey = null;
															var pidValue = null;
															//判断是否有
															//select areaId ID,areaName CN,parentid p_id from table//如果存在ID，CN之外的字段则认为是关联的,并且指定了父节点是谁
															if (objects.length >= 2) {//
																var object = objects[1];
																for (i in object) {
																	//console.log(i);
																	if (i != 'id'
																			&& i != 'cn') {
																		pidKey = i;
																		break;
																	}
																}
															}

															if (pidKey != null) {
																//如果存在 
																$(
																		'select[id="a_id"]')
																		.attr(
																				"pid",
																				pidKey);
																pidValue = $(
																		'select[id="'
																				+ pidKey
																				+ '"]')
																		.val();
															}
															//检测父节点是否有值才渲染|| 无父节点也渲染
															console
																	.log('pidValue:'
																			+ pidValue);
															if (pidKey == null
																	|| (pidValue != null && pidValue != '')) {

																$(objects)
																		.each(
																				function(
																						index) {
																					if (index == 0) {
																						$(
																								"#a_id")
																								.append(
																										'<option value="">请选择</option>');
																					}

																					var object = objects[index];
																					if (pidKey == null) {
																						var optionStr = "";
																						optionStr += "<option value='" + object.id + "'>"
																								+ object.cn
																								+ "</option>";
																						$(
																								"#a_id")
																								.append(
																										optionStr);
																					} else {
																						if (object[pidKey] == pidValue) {
																							var optionStr = "";
																							optionStr += "<option value='" + object.id + "'>"
																									+ object.cn
																									+ "</option>";
																							$(
																									"#a_id")
																									.append(
																											optionStr);
																						}
																					}
																				});

																if ('' != '')
																	$(
																			'select[id="a_id"]')
																			.val(
																					''
																							.split(','));

															}
															renderForm();//由于前部还有一个重置options的操作
														}
													});
										}
										a_id_init();
										layui
												.use(
														[ 'form' ],
														function() {
															var form = layui.form;
															//选中事件
															form
																	.on(
																			'select(a_id)',
																			function(
																					data) {
																				console
																						.log(data);
																				//检查是否有子节点需要刷新数据
																				var pid = $('select[pid="a_id"]');
																				if (pid.length != 0) {
																					//关联初始
																					var funName = pid
																							.attr("id")
																							+ "_init";
																					//a_id_init
																					if (isExitsFunction(funName)) {
																						//funName();
																						//alert(funName);
																						//dataDone(res, curr, count,is_single);
																						eval(funName
																								+ "();");

																					}
																				}

																			});
														});
									</script>
								</div>
							</div>

						</div>




						<div class="layui-row layui-col-space10 layui-form-item">
							<div class="layui-col-lg12}">
								<label class="layui-form-label">性别</label>
								<div class="layui-input-block">

									<select id="sexy" name="sexy" lay-filter="sexy"
										url="/widget/comboJson/demo2_test-sexy" lay-verify=""
										lay-search>
										<!--         <option value="">请选择</option> -->

										<!--         <option value="0">写作</option> -->
										<!--         <option value="1" >阅读</option> -->
										<!--         <option value="2">游戏</option> -->
										<!--         <option value="3">音乐</option> -->
										<!--         <option value="4">旅行</option> -->

									</select>
									<script type="text/javascript">
										var sexy_init = function() {
											//清除本节点数据（子节点也要执行初始）
											$("#sexy").empty();
											//检查是否有子节点需要刷新数据
											var pid = $('select[pid="sexy"]');
											if (pid.length != 0) {
												//关联初始
												var funName = pid.attr("id")
														+ "_init";
												//sexy_init
												if (isExitsFunction(funName)) {
													//funName();
													//alert(funName);
													//dataDone(res, curr, count,is_single);
													eval(funName + "();");

												}
											}

											// 手动赋值(可能存在级联关系)
											$
													.ajax({
														url : '/widget/comboJson/demo2_test-sexy',
														type : 'get',
														success : function(data) {

															var objects = eval(data);
															var pidKey = null;
															var pidValue = null;
															//判断是否有
															//select areaId ID,areaName CN,parentid p_id from table//如果存在ID，CN之外的字段则认为是关联的,并且指定了父节点是谁
															if (objects.length >= 2) {//
																var object = objects[1];
																for (i in object) {
																	//console.log(i);
																	if (i != 'id'
																			&& i != 'cn') {
																		pidKey = i;
																		break;
																	}
																}
															}

															if (pidKey != null) {
																//如果存在 
																$(
																		'select[id="sexy"]')
																		.attr(
																				"pid",
																				pidKey);
																pidValue = $(
																		'select[id="'
																				+ pidKey
																				+ '"]')
																		.val();
															}
															//检测父节点是否有值才渲染|| 无父节点也渲染
															console
																	.log('pidValue:'
																			+ pidValue);
															if (pidKey == null
																	|| (pidValue != null && pidValue != '')) {

																$(objects)
																		.each(
																				function(
																						index) {
																					if (index == 0) {
																						$(
																								"#sexy")
																								.append(
																										'<option value="">请选择</option>');
																					}

																					var object = objects[index];
																					if (pidKey == null) {
																						var optionStr = "";
																						optionStr += "<option value='" + object.id + "'>"
																								+ object.cn
																								+ "</option>";
																						$(
																								"#sexy")
																								.append(
																										optionStr);
																					} else {
																						if (object[pidKey] == pidValue) {
																							var optionStr = "";
																							optionStr += "<option value='" + object.id + "'>"
																									+ object.cn
																									+ "</option>";
																							$(
																									"#sexy")
																									.append(
																											optionStr);
																						}
																					}
																				});

																if ('' != '')
																	$(
																			'select[id="sexy"]')
																			.val(
																					''
																							.split(','));

															}
															renderForm();//由于前部还有一个重置options的操作
														}
													});
										}
										sexy_init();
										layui
												.use(
														[ 'form' ],
														function() {
															var form = layui.form;
															//选中事件
															form
																	.on(
																			'select(sexy)',
																			function(
																					data) {
																				console
																						.log(data);
																				//检查是否有子节点需要刷新数据
																				var pid = $('select[pid="sexy"]');
																				if (pid.length != 0) {
																					//关联初始
																					var funName = pid
																							.attr("id")
																							+ "_init";
																					//sexy_init
																					if (isExitsFunction(funName)) {
																						//funName();
																						//alert(funName);
																						//dataDone(res, curr, count,is_single);
																						eval(funName
																								+ "();");

																					}
																				}

																			});
														});
									</script>
								</div>
							</div>
						</div>
						<div class="layui-row layui-col-space10 layui-form-item">
							<div class="layui-col-lg12}">
								<label class="layui-form-label">手机号</label>
								<div class="layui-input-block">

									<input type="text" id="mobile" name="mobile" value=""
										placeholder="" lay-verify="" autocomplete="off"
										class="layui-input">
								</div>
							</div>
						</div>
						<div class="layui-row layui-col-space10 layui-form-item">
							<div class="layui-col-lg12}">
								<label class="layui-form-label">备注</label>
								<div class="layui-input-block">

									<textarea class="layui-textarea" id="remark" name="remark"
										style="width: 98%; height: 20px;" placeholder=""
										lay-verify="length[10~]"></textarea>

								</div>
							</div>
						</div>
						<div class="layui-row layui-col-space10 layui-form-item">
							<div class="layui-col-lg12}">
								<label class="layui-form-label">审核状态</label>
								<div class="layui-input-block">

									<!-- 审核模块需要用到 -->
									<div id="mycheck_shenhe_status">
										<input type="hidden" name="shenhe_status" value="1">

										<!-- <input type="radio" name="sex" value="男" title="男" checked="">
      <input type="radio" name="sex" value="女" title="女">
      <input type="radio" name="sex" value="禁" title="禁用" disabled="">  -->

									</div>
									<script>
										// JS 可以干预控件所在页面的任何效果

										$(function() {

											var idName = "mycheck_shenhe_status";
											var $checks = $('#' + idName);
											var $checkValue = $checks
													.find("input:hidden");

											var readonly = false;

											// 加载数据(复选框其实和下拉一样，只是展现方式不一样，所以直接用下拉的API获取数据)
											var url = "/widget/comboJson/demo2_test-shenhe_status";
											$
													.ajax({
														type : 'get',
														async : true,
														url : url,
														dataType : "json",
														success : function(json) {

															// 生成复选框Dom
															$
																	.each(
																			json,
																			function(
																					index,
																					o) {
																				$(
																						'<input type="radio" name="shenhe_status_radio" lay-filter="shenhe_status_radio" value="'+o.id+'" title="'+o.cn+'" >')
																						.appendTo(
																								$checks);
																				//$("<label><input type=\"radio\" value=\"" + o.id + "\">" + o.cn + "&nbsp;</label>").appendTo($checks);
																			});
															// 初始化选中
															var vals = $checkValue
																	.val()
																	.split(",");

															$checks
																	.find(
																			'input:radio')
																	.each(
																			function(
																					i,
																					o) {
																				console
																						.log($(
																								o)
																								.val());

																				if (readonly) {
																					o.disabled = true;
																				}

																				if ($checkValue
																						.val() == $(
																						o)
																						.val()) {
																					o.checked = true;
																					//审核界面才需此效果
																					if (PAGE_TYPE == "examine")
																						o.disabled = true;

																				}

																			});

															// 绑定radio事件
															layui
																	.use(
																			[ 'form' ],
																			function() {
																				var form = layui.form;
																				form
																						.on(
																								'radio(shenhe_status_radio)',
																								function(
																										data) {
																									//console.log(data.elem); //得到radio原始DOM对象
																									//console.log(data.value); //被点击的radio的value值
																									$checkValue
																											.val(data.value);
																								});
																			});

															renderForm();

														},
														error : function() {
															alert('复选框加载数据失败,URL='
																	+ url);
														}
													});

										});
									</script>
								</div>
							</div>
						</div>

						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit="" lay-filter="submit">
									立即提交</button>
							</div>
						</div>


					</div>
				</div>
			</div>

			<input type="hidden" name="user_id" value="1" />



		</div>
		</div>
		</div>
	</form>
	<script>
		layui.use([ 'form', 'code' ], function() {
			var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
			$ = layui.$;

			// 代码块
			layui.code({
				title : 'html',
				encode : true,
				about : false

			});

			// 手动赋值
			//$('select[name="简化多选+搜索+大小写敏感"]').val(['sing1', 'movie2']);
			form.render();

			//但是，如果你的HTML是动态生成的，自动渲染就会失效
			//因此你需要在相应的地方，执行下述方法来手动渲染，跟这类似的还有 element.init();
			form.on('submit(submit)', function(data) {
				//console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
				//console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
				//console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
				//console.log(syntaxHighlight(data.field));

				//提交数据
				submitNow(data);
				return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});

		});

		// json 格式化+高亮
		function syntaxHighlight(json) {
			if (typeof json != 'string') {
				json = JSON.stringify(json, undefined, 2);
			}
			json = json.replace(/&/g, '&').replace(/</g, '<')
					.replace(/>/g, '>');
			return json
					.replace(
							/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
							function(match) {
								var cls = 'number';
								if (/^"/.test(match)) {
									if (/:$/.test(match)) {
										cls = 'key';
									} else {
										cls = 'string';
									}
								} else if (/true|false/.test(match)) {
									cls = 'boolean';
								} else if (/null/.test(match)) {
									cls = 'null';
								}
								return '<span class="' + cls + '">' + match
										+ '</span>';
							});
		}
	</script>



	<script type="text/javascript">
		var $form = $('#addFormdemo2_test');
		var submitNow = function(data) {
			var myform = $.getFormParasObj($form);
			myform['PAGE_TYPE'] = PAGE_TYPE;
			$.post('/form/doAdd/demo2_test', myform, function(result) {
				if (result.success) {

					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index);

					parent.reload('demo2_test_grid');
				} else {
					//alert$.alert($pjq, result.msg);

					//layer.alert("操作失败:"+result.msg);

					layer.alert(result.msg, {
						icon : 2
					});

				}
			}, 'json');
		};

		$(function() {
			// 禁用表单，注销事件，仅供查看
			$(document).ready(function() {
				//$(this).find('input,textarea,select').attr("readonly",true);
				//$(this).find('input,i,div').unbind();
			});
		});
	</script>
</body>



</html>